﻿// Author: Prasanna V. Loganathar
// Project: Edi.Core
// 
// Copyright 2014 Launchark. All Rights Reserved.
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//  
// Created: 1:14 AM 15-05-2014

namespace Edi.Common.Infrastructure
{
    using System;
    using System.IO;

    public interface IFileSystem
    {
        StorageZone DefaultStorageZone { get; set; }
        string ApplicationStorePath { get; set; }
        string LocalStorePath { get; set; }
        string TempStorePath { get; set; }
        string RoamingStorePath { get; set; }
        string SharedStorePath { get; set; }
        string CacheStorePath { get; set; }
        Stream CreateFile(string fileName, StorageZone zone = StorageZone.Unspecified);
        void DeleteFile(string fileName, StorageZone zone = StorageZone.Unspecified);
        bool FileExists(string fileName, StorageZone zone = StorageZone.Unspecified);
        bool DirectoryExists(string dirName, StorageZone zone = StorageZone.Unspecified);
        void CreateDirectory(string dirName, StorageZone zone = StorageZone.Unspecified);
        void DeleteDirectory(string dirName, StorageZone zone = StorageZone.Unspecified, bool recursive = false);

        void MoveFile(
            string srcFileName,
            string destFileName,
            StorageZone srcZone,
            StorageZone destZone = StorageZone.Unspecified);

        void MoveDirectory(
            string srcDirName,
            StorageZone srcZone,
            string destDirName,
            StorageZone destZone = StorageZone.Unspecified);

        IFileProperty GetProperties(string fileName, StorageZone zone = StorageZone.Unspecified);
        Stream GetStream(string fileName, FileAccess accessMode, StorageZone zone = StorageZone.Unspecified);
    }

    public interface IFileProperty
    {
        string Name { get; }
        string Extension { get; }
        string Path { get; }
        ulong Size { get; }
        string Type { get; }
        DateTimeOffset LastModifiedDate { get; }
        DateTimeOffset CreatedDate { get; }
        DateTimeOffset LastAccessedDate { get; }
    }

    public enum StorageZone : byte
    {
        Unspecified = 0x00,
        Application = 0x01,
        Local = 0x02,
        Roaming = 0x03,
        Cache = 0x04,
        Temp = 0x05,
        Shared = 0x06,
        Other = 0x07
    }

    /// <summary>
    ///     Defines constants for read, write, or read/write access to a file.
    /// </summary>
    [Flags]
    public enum FileAccess : byte
    {
        /// <summary>
        ///     Read only access to the file.
        /// </summary>
        Read = 0x1,

        /// <summary>
        ///     Write only access to the file.
        /// </summary>
        Write = 0x02,

        /// <summary>
        ///     Read and write access.
        /// </summary>
        ReadWrite = Read | Write,
    }
}